// function deployFunction() {
//     console.log("this is a deploy function")
// }

const { network } = require("hardhat")
const {developmentChains, networkConfig, LOCK_TIME, CONFIRMATIONS} = require("../helper-hardhat-config")
// module.exports.default=deployFunction
// module.exports= async(hre) => {
//     const getNamdeAccounts = hre.getNamdeAccounts
//     const deployments = hre.deployments
//     console.log("this is a deploy function")
// }

module.exports= async({getNamedAccounts, deployments}) => {
    const {firstAccount} = await getNamedAccounts()
    const {deploy} = deployments
    console.log("部署合约人：",firstAccount)
    let dataFeedAddr
    let confirmations
    // let  tokenAddr  
    const token = await deployments.get("MyToken")    
    const tokenAddr = token.address
    console.log("tokenAddr:",tokenAddr)

    if(developmentChains.includes(network.name)) {
        const mockV3Aggregator = await deployments.get("MockV3Aggregator")    
        dataFeedAddr = mockV3Aggregator.address
        confirmations = 0
    } else {
        dataFeedAddr = networkConfig[network.config.chainId].ethUsdDataFeed
        confirmations = CONFIRMATIONS
    }


    console.log("dataFeedAddr",dataFeedAddr)
    const wishContract = await deploy("Wish", {
        from: firstAccount,
        args: [tokenAddr, dataFeedAddr],
        log: true,
        waitConfirmations: confirmations
    })


    // remove deployments directory or add --reset flag if you redeploy contract


    if(network.config.chainId == 11155111 && process.env.EHTERSCAN_API_KEY) {
        await hre.run("verify:verify", {
            address: wishContract.address,
            constructorArguments: [tokenAddr, dataFeedAddr],
          });        
    } else {
        console.log("Network is not sepolia, verification skipped...")
    }


}

module.exports.tags = ["all", "wish"]